/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import mappers.ClubMapper;
import handler.DatabaseConnection;
import control.SBU;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import model.Club;
import model.Event;
import model.Match;
import model.Player;

/**
 *
 * @author Benjamin
 */
public class EmployeeGui extends javax.swing.JFrame {

    private SBU sbu;

    public EmployeeGui() {

        initComponents();
        setup();
    }

    private void setup() {
        DatabaseConnection.getDbInstance().createConnection();

        if (DatabaseConnection.getDbInstance().hasConnection() == true) {

            sbu = SBU.getInstance();

            //Nulstil alle combobokse.
            resetScreen();

            //fyld de 3 divisioner ind i combobox 1.
            for (int i = 0; i < 3; i++) {
                jComboBox1.addItem("Division " + (i + 1));
                jComboBox6.addItem("Division " + (i + 1));
            }

            //Tabs tillades igen.
            jTabbedPane1.setEnabled(true);

        } else {
            jTabbedPane1.setSelectedIndex(0);
            jTabbedPane1.setEnabled(false);
        }
    }

    private void resetScreen() {
        jComboBox2.setEnabled(false);
        jComboBox3.setEnabled(false);
        jComboBox4.setEnabled(false);
        jComboBox5.setEnabled(false);
        jTextField5.setEnabled(false);
        jButton3.setEnabled(false);
        jButton2.setEnabled(false);

        //Slet også alt indhold i de deaktiverede elementer.
        jComboBox2.removeAllItems();
        jComboBox3.removeAllItems();
        jComboBox4.removeAllItems();
        jComboBox5.removeAllItems();
        jTextField5.setText("");

        //Genopret standard items.
        jComboBox2.addItem("Vælg runde");
        jComboBox3.addItem("Vælg kamp");
        jComboBox4.addItem("Vælg spiller");
        jComboBox5.addItem("Vælg begivenhed");
        jComboBox5.addItem("Rødt kort");
        jComboBox5.addItem("Gult kort");
        jComboBox5.addItem("Selvmål");
        jComboBox5.addItem("Scoring");

        jComboBox1.setSelectedIndex(0);

    }

    public ArrayList<Club> sortClubs(ArrayList<Club> unsortedClubs) {
        ArrayList<Club> sortedClubs = new ArrayList<>();
        while (!unsortedClubs.isEmpty()) {
            //Klubben med flest point.
            Club bestClub = unsortedClubs.get(0);
            //Klubben med flest points index.
            int bestClubIndex = 0;

            for (int i = 0; i < unsortedClubs.size(); i++) {
                if (bestClub.getPoints() < unsortedClubs.get(i).getPoints()) {
                    bestClub = unsortedClubs.get(i);
                    bestClubIndex = i;
                }
            }

            sortedClubs.add(bestClub);
            unsortedClubs.remove(bestClubIndex);
        }

        return sortedClubs;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jTextField6 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jButton5 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jComboBox4 = new javax.swing.JComboBox();
        jTextField5 = new javax.swing.JTextField();
        jComboBox5 = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jPanel5 = new javax.swing.JPanel();
        jComboBox6 = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTabbedPane1.setPreferredSize(new java.awt.Dimension(745, 500));
        jTabbedPane1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTabbedPane1FocusGained(evt);
            }
        });

        jPanel1.setLayout(null);

        jLabel1.setText("Host:");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(10, 20, 70, 14);

        jTextField1.setText("localhost");
        jTextField1.setPreferredSize(new java.awt.Dimension(300, 30));
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        jPanel1.add(jTextField1);
        jTextField1.setBounds(140, 10, 580, 30);

        jLabel2.setText("Port:");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(10, 50, 90, 14);

        jTextField2.setText("3306");
        jTextField2.setPreferredSize(new java.awt.Dimension(300, 30));
        jPanel1.add(jTextField2);
        jTextField2.setBounds(140, 40, 580, 30);

        jLabel3.setText("Brugernavn:");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(10, 104, 120, 20);

        jLabel4.setText("Kodeord:");
        jPanel1.add(jLabel4);
        jLabel4.setBounds(10, 140, 90, 14);

        jTextField3.setText("fodbolddb");
        jTextField3.setPreferredSize(new java.awt.Dimension(300, 30));
        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });
        jPanel1.add(jTextField3);
        jTextField3.setBounds(140, 70, 580, 30);

        jTextField4.setText("root");
        jTextField4.setPreferredSize(new java.awt.Dimension(300, 30));
        jPanel1.add(jTextField4);
        jTextField4.setBounds(140, 100, 580, 30);

        jButton1.setText("Opret forbindelse");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);
        jButton1.setBounds(540, 170, 180, 40);

        jTextField6.setText("root");
        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });
        jPanel1.add(jTextField6);
        jTextField6.setBounds(140, 130, 580, 30);

        jLabel6.setText("Databasenavn");
        jPanel1.add(jLabel6);
        jLabel6.setBounds(10, 80, 80, 14);

        jTabbedPane1.addTab("Forbindelse til database", jPanel1);

        jPanel3.setLayout(null);

        jButton5.setText("Opret kampprogram");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton5);
        jButton5.setBounds(270, 160, 170, 50);

        jLabel7.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jPanel3.add(jLabel7);
        jLabel7.setBounds(270, 220, 170, 60);

        jTabbedPane1.addTab("Ny sæson", jPanel3);

        jPanel2.setLayout(null);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Vælg division" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox1);
        jComboBox1.setBounds(10, 10, 160, 20);

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Vælg runde" }));
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox2);
        jComboBox2.setBounds(180, 10, 140, 20);

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Vælg kamp" }));
        jComboBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox3ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox3);
        jComboBox3.setBounds(330, 10, 370, 20);

        jButton2.setText("Afslut kamp");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton2);
        jButton2.setBounds(550, 50, 150, 23);

        jButton3.setText("Næste begivenhed");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton3);
        jButton3.setBounds(380, 50, 150, 23);

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "vælg spiller" }));
        jComboBox4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox4ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox4);
        jComboBox4.setBounds(10, 50, 160, 20);

        jTextField5.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextField5FocusGained(evt);
            }
        });
        jTextField5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField5ActionPerformed(evt);
            }
        });
        jPanel2.add(jTextField5);
        jTextField5.setBounds(330, 40, 40, 30);

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox5ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox5);
        jComboBox5.setBounds(180, 50, 140, 20);

        jLabel5.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jPanel2.add(jLabel5);
        jLabel5.setBounds(10, 80, 160, 80);

        jTabbedPane1.addTab("Kamprapportering", jPanel2);

        jPanel4.setLayout(null);

        jTextArea1.setEditable(false);
        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jPanel4.add(jScrollPane1);
        jScrollPane1.setBounds(10, 10, 700, 440);

        jTabbedPane1.addTab("Kamprapport", jPanel4);

        jPanel5.setLayout(null);

        jComboBox6.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Vælg Division" }));
        jComboBox6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox6ActionPerformed(evt);
            }
        });
        jPanel5.add(jComboBox6);
        jComboBox6.setBounds(10, 10, 120, 20);

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane2.setViewportView(jTextArea2);

        jPanel5.add(jScrollPane2);
        jScrollPane2.setBounds(140, 10, 570, 440);

        jTabbedPane1.addTab("Turneringsstilling", jPanel5);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 725, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed

        if (!(jComboBox1.getSelectedIndex() <= 0)) {
            //Før der tilføjes til comboboksen med runder, slettes alt i den.
            jComboBox2.removeAllItems();
            jComboBox2.setEnabled(false);
            jComboBox3.removeAllItems();
            jComboBox3.setEnabled(false);
            jComboBox4.removeAllItems();
            jComboBox4.setEnabled(false);
            jComboBox2.addItem("Vælg runde");
            jComboBox3.addItem("Vælg kamp");
            jComboBox4.addItem("Vælg spiller");

            jLabel5.setText("");
            int division = jComboBox1.getSelectedIndex();
            int rounds = sbu.getNumRounds(division);

            for (int i = 1; i <= rounds; i++) {
                jComboBox2.addItem("Runde " + (i));
                jComboBox2.setMaximumRowCount(rounds);
            }

            jComboBox2.setEnabled(true);

        }
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed

        //Igen fjernes alt i den kommende comboboks.
        //If-sætningen sørger for at dne kun refresher hvis der er andet end
        //start elementet i comboboksen. Det er ikke kun når man vælger
        //et element at der sker en action i comboboksen, det er når der
        //foretages en handling i denne.
        if (jComboBox3.getItemCount() > 1) {
            jComboBox3.removeAllItems();
            jComboBox3.addItem("Vælg kamp");
            jComboBox4.removeAllItems();
            jComboBox4.addItem("Vælg spiller");
        }

        if (!(jComboBox2.getSelectedIndex() <= 0)) {

            int selectedDivision = 1;
            int selectedRound = 1;

            if (!(jComboBox1.getSelectedIndex() == 0)) {
                selectedDivision = jComboBox1.getSelectedIndex();
            }
            if (!(jComboBox2.getSelectedIndex() == 0)) {
                selectedRound = jComboBox2.getSelectedIndex();
            }
            ArrayList<Match> selectedMatches = sbu.getMatches(selectedDivision, selectedRound);

            for (int i = 0; i < selectedMatches.size(); i++) {

                jComboBox3.addItem(selectedMatches.get(i));

            }
            jComboBox3.setMaximumRowCount(jComboBox3.getItemCount());
            //jComboBox1's actionlistener laver en action når den udfører
            //removeAllItems(); dette skal kontrolleres.
            if (jComboBox2.isEnabled()) {
                jComboBox3.setEnabled(true);
            }
        }

    }//GEN-LAST:event_jComboBox2ActionPerformed

    private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed
        if (!(jComboBox3.getSelectedIndex() <= 0)) {
            Match selectedMatch = (Match) jComboBox3.getSelectedItem();

            //Hvis den valgte kamp ikke er afsluttet skal den næste combobox fyldes
            //med spillere fra hjemmehold og udehold.
            if (selectedMatch.isEnded() == false) {
                jLabel5.setText("");
                jComboBox4.removeAllItems();
                jComboBox4.addItem("Vælg spiller");

                //Henter spillere for den valgte kamp.
                ArrayList<Player> players = sbu.getPlayers(selectedMatch);
                for (int i = 0; i < players.size(); i++) {
                    jComboBox4.addItem(players.get(i));
                }

                jComboBox4.setMaximumRowCount(jComboBox3.getItemCount());
                if (jComboBox3.isEnabled()) {
                    jComboBox4.setEnabled(true);
                    jButton2.setEnabled(true);
                }
            //Hvis den kamp man vælger er afsluttet skal den gå til kamprapport fanen
            //og vise alle begivenheder på kampen.
            } else {
                String str = selectedMatch.getHomeTeam() + " mod " + selectedMatch.getAwayTeam() + "\n";
                str += "--------------------------------------------------------------\n";
                jTextArea1.setText(str);
                ArrayList<Event> events = sbu.getEvents(selectedMatch);
                for (int i = 0; i < events.size(); i++) {
                    jTextArea1.append(events.get(i).toString() + "\n");
                }
                
                //Skifter fane til kamprapport fanen.
                jTabbedPane1.setSelectedIndex(3);

            }
        }
    }//GEN-LAST:event_jComboBox3ActionPerformed

    private void jComboBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox4ActionPerformed
        //Sætter selectedPlayer til den valgte spiller i comboboxen.
        if (!(jComboBox4.getSelectedIndex() <= 0)) {
            //Player selectedPlayer = (Player) jComboBox4.getSelectedItem();

            if (jComboBox4.isEnabled()) {
                jComboBox5.setEnabled(true);
                jTextField5.setEnabled(true);
                jTextField5.setText("1-90");
            }
        }
    }//GEN-LAST:event_jComboBox4ActionPerformed

    private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField5ActionPerformed

    }//GEN-LAST:event_jTextField5ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        try {
            //Henter den valgte spiller fra listen af spillere.
            Player selectedPlayer = (Player) jComboBox4.getSelectedItem();
            //Henter den valgte match fra listen af matches.
            Match selectedMatch = (Match) jComboBox3.getSelectedItem();

            //Køre getCount for at finde ud af hvor mange rækker der er i occasion tabelen.
            int id = SBU.getInstance().getCount() + 1;
            String type = jComboBox5.getSelectedItem() + "";
            int moment;

            //Henter spillerens og matchens id for at kunne opfylde fremmednøgle -
            //kravene i databasen.
            int playerid = selectedPlayer.getId();
            int matchid = selectedMatch.getMatchId();

            //Man skal indtaste en minutværdi fra 0 til og med 90, for en kamps længde. 
            moment = Integer.parseInt(jTextField5.getText());
            if (moment >= 0 && moment <= 90) {
                SBU.getInstance().addEvent(id, type, moment, playerid, matchid);

                //Udvisker og gør klar til den næste indtastning af events, 
                //og sørger for at fortælle at de valgte indstillinger er gemt.
                jTextField5.setText("");
                jLabel5.setText("");
                jComboBox5.setSelectedIndex(0);
                if ("".equals(jTextField5.getText())) {
                    jLabel5.setText("Gemt");
                    jButton3.setEnabled(false);
                }
            } else {
                jTextField5.setText("Indtast min fra 0-90.");
                jLabel5.setText("");
            }

            //Fanger exceptions på indtastning af andet en et nummer i jTextField5
            //og når der ikke vælges et event objekt. Sørger for at udskrive en prompt.
        } catch (NumberFormatException ex) {
            jLabel5.setText("Indtast et heltal fra 0 - 90.");
        } catch (ClassCastException ex) {
            jLabel5.setText("Vælg kamp og spiller.");
        }

        //jButton3.setEnabled(false);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        try {
            
            //Henter den valgte kamp fra comboboxen og de linkede events.
            Match selectedMatch = (Match) jComboBox3.getSelectedItem();
            
            //Henter alle begivenheder på den valgte kamp.
            sbu.getEvents(selectedMatch);
            
            //Afslutter kampen.
            sbu.endMatch(selectedMatch);
            resetScreen();
            
            //Lader brugeren vide at kampen er afsluttet, så han ikke spekulerer.
            jLabel5.setText("Kampen er nu afsluttet.");

            //Fanger en ClassCastException der sker når SBU ikke kan hente et objekt,
            //altså når brugeren ikke vælger en kamp.
        } catch (ClassCastException ex) {
            
            //Hvis den valgte combobox er den "default" værdi, som leder til en 
            //ClassCastException, så udskrives der hhv. vælg "noget" til brugeren.
            if (jComboBox3.getItemAt(0) == jComboBox3.getSelectedItem()) {
                jLabel5.setText("Vælg kamp");
            }
            if (jComboBox2.getItemAt(0) == jComboBox2.getSelectedItem()) {
                jLabel5.setText("Vælg runde");
            }
            if (jComboBox1.getItemAt(0) == jComboBox1.getSelectedItem()) {
                jLabel5.setText("Vælg division");
            }
        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        sbu.createMatchlist();
            jLabel7.setText("Kampprogrammet er\n oprettet.");
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jComboBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox5ActionPerformed
        if (!(jComboBox5.getSelectedIndex() == 0)) {
            jButton3.setEnabled(true);
        }
        if (!(jComboBox5.getSelectedIndex() >= 1)) {
            jButton3.setEnabled(false);
        }

    }//GEN-LAST:event_jComboBox5ActionPerformed


    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            String filename = "DbLogInfo.txt";
            File file = new File(filename);
            PrintWriter pw = new PrintWriter(file);
            pw.println("Host:");
            pw.println(jTextField1.getText());
            pw.println("Port:");
            pw.println(jTextField2.getText());
            pw.println("Dbnavn:");
            pw.println(jTextField3.getText());
            pw.println("User:");
            pw.println(jTextField4.getText());
            pw.println("Password:");
            pw.println(jTextField6.getText());
            pw.close();
        } catch (IOException ex) {
            System.out.println("fodbold - DbError - JButton1ActionPerformed() Det var ikke muligt at skrive til filen: " + ex.getMessage());
        }

        setup();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField3ActionPerformed

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField6ActionPerformed

    private void jComboBox6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox6ActionPerformed
        jTextArea2.setText("");

        if (!(jComboBox6.getSelectedIndex() <= 0)) {

            int division = jComboBox6.getSelectedIndex();
            ArrayList<Club> unsortedClubs = sbu.getClubs(division);

            ArrayList<Club> sortedClubs = sortClubs(unsortedClubs);

            for (int i = 0; i < sortedClubs.size(); i++) {
                jTextArea2.append(sortedClubs.get(i) + " " + sortedClubs.get(i).getPoints() + "\n");
            }
        }
    }//GEN-LAST:event_jComboBox6ActionPerformed

    private void jTextField5FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField5FocusGained
        jTextField5.setText("");
    }//GEN-LAST:event_jTextField5FocusGained

    private void jTabbedPane1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTabbedPane1FocusGained
        //Nulstiller den label der underetter brugeren når kampprogrammet er 
        //oprettet korrekt.
        jLabel7.setText("");
    }//GEN-LAST:event_jTabbedPane1FocusGained

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EmployeeGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EmployeeGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EmployeeGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EmployeeGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EmployeeGui().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JComboBox jComboBox6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    // End of variables declaration//GEN-END:variables
}
